# import pandas as pd
#
# # 定义文件路径列表
# file_paths = [
#     r"C:\Users\20231112\Downloads\11.27\lxx1.xlsx",
#     r"C:\Users\20231112\Downloads\11.27\lxx2.xlsx",
#     r"C:\Users\20231112\Downloads\11.27\lxx3.xlsx",
#     r"C:\Users\20231112\Downloads\11.27\lxx4.xlsx",
#     r"C:\Users\20231112\Downloads\11.27\lxx5.xlsx",
#     r"C:\Users\20231112\Downloads\11.27\lxx6.xlsx"
# ]
#
# # 用于存储所有数据的列表
# data_frames = []
#
# # 逐个读取文件并添加到列表中
# for path in file_paths:
#     try:
#         df = pd.read_excel(path)
#         data_frames.append(df)
#     except Exception as e:
#         print(f"读取文件 {path} 失败: {e}")
#
# # 合并所有数据
# if data_frames:
#     # 合并数据并筛选
#     combined_df = pd.concat(data_frames, ignore_index=True)
#
#     # 筛选日期为"全部"的记录
#     filtered_df = combined_df[combined_df['日期'] == '全部']
#
#     # 只保留需要的两列并去重
#     result_df = filtered_df[['抖音号名称', '抖音号ID']].drop_duplicates()
#
#     # 删除指定的抖音号名称
#     exclude_names = ['饱饱吃不饱', '大馋丫头可可']
#     result_df = result_df[~result_df['抖音号名称'].isin(exclude_names)]
#
#     # 保存结果到Excel文件
#     result_df.to_excel(r'C:\Users\20231112\Downloads\11.27\投流消耗配置表\内部投流达人.xlsx', index=False)
#     print("处理完成！结果已保存为 '内部投流达人.xlsx'")
# else:
#     print("未找到任何有效文件。")


# V1.0

import pandas as pd
import os
from datetime import datetime

current_date = datetime.now().strftime("%m.%d")

file_paths = [
    rf"C:\Users\20231112\Downloads\{current_date}\lxx1.xlsx",
    rf"C:\Users\20231112\Downloads\{current_date}\lxx2.xlsx",
    rf"C:\Users\20231112\Downloads\{current_date}\lxx3.xlsx",
    rf"C:\Users\20231112\Downloads\{current_date}\lxx4.xlsx",
    rf"C:\Users\20231112\Downloads\{current_date}\lxx5.xlsx",
    rf"C:\Users\20231112\Downloads\{current_date}\lxx6.xlsx"
]

output_dir = rf"C:\Users\20231112\Downloads\{current_date}\投流消耗配置表"
os.makedirs(output_dir, exist_ok=True)

# 用于存储所有数据的列表
data_frames = []

# 逐个读取文件并添加到列表中
for path in file_paths:
    try:
        df = pd.read_excel(path)
        data_frames.append(df)
    except Exception as e:
        print(f"读取文件 {path} 失败: {e}")

# 合并所有数据
if data_frames:
    # 合并数据并筛选
    combined_df = pd.concat(data_frames, ignore_index=True)

    # 筛选日期为"全部"的记录
    filtered_df = combined_df[combined_df['日期'] == '全部']

    # 只保留需要的两列并去重
    result_df = filtered_df[['抖音号名称', '抖音号ID']].drop_duplicates()

    # 删除指定的抖音号名称
    exclude_names = ['饱饱吃不饱', '大馋丫头可可']
    result_df = result_df[~result_df['抖音号名称'].isin(exclude_names)]

    # 保存结果到Excel文件
    result_df.to_excel(rf"{output_dir}\内部投流达人.xlsx", index=False)
    print("处理完成！结果已保存为 '内部投流达人.xlsx'")
else:
    print("未找到任何有效文件。")
